<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" id="rname" placeholder="请输入搜索的角色" />
                </div>

                <a class="layui-btn search_btn" data-type="reload"  id="searchVal">搜索</a>
            </div>
            <shiro:hasPermission name="role:add">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal addRole_btn" >添加角色</a>
                </div>
            </shiro:hasPermission>

        </form>
    </blockquote>
    <table id="roleList" lay-filter="roleList"></table>
    <!--操作-->
    <script type="text/html" id="roleListBar">
        <%--<shiro:hasPermission name="role:del">--%>
            <%--<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>--%>
        <%--</shiro:hasPermission>--%>

        <shiro:hasPermission name="role:assign">
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="assignRight">分配权限</a>
        </shiro:hasPermission>


    </script>
</form>
<script type="text/javascript" src="/static/layui/layui/layui.js"></script>
<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            laydate=layui.laydate;

        //角色列表
        var tableIns = table.render({
            elem: '#roleList',
            url : '/role/roles',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limits : [5,10,15,20,25],
            limit : 5,
            id : "roleListTable",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                {field: 'rname', title: '角色', minWidth:100, align:"center"},

                {title: '操作', minWidth:175, templet:'#roleListBar',fixed:"right",align:"center"}
            ]]
        });

        //搜索
        $("#searchVal").click(function () {
            var rname=$('#rname').val();
            console.log(rname);
            tableIns.reload({
                where:{
                    rname:rname,
                }
            })
        });

        $('.addRole_btn').click(function () {
            layui.layer.open({
                title:"添加角色",
                type: 2,
                content: '/page/sys/roleAdd.jsp',
                shade:0.3,
                anim:0,
                area:["40%","40%"],
                maxmin:true,
                success:function (res) {
                    console.log(res+"添加");
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回角色列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },1000)
                }
            });
        })
        table.on("tool(roleList)",function (obj) {
            var data=obj.data;
            switch (obj.event){
                //权限分配
                case "assignRight":
                    assignRight(data.rid);
                    break;
            }
        })

        //选择表格中的按钮添加click事件
        function assignRight(rid) {
            layui.layer.open({
                title:"权限分配",
                type: 2,
                content: '/page/sys/assignPer.jsp',
                shade:0.3,
                anim:0,
                area:["30%","70%"],
                maxmin:true,
                success:function (layero,index) {
                    var body=layui.layer.getChildFrame('body',index);
                    body.contents().find("#roleIdHiden").val(rid);
                }

            });
        }

    })

</script>
</body>
</html>